package com.kaishengit.dao;

import java.util.ArrayList;
import java.util.List;

import com.kaishengit.dao.core.BaseDao;
import com.kaishengit.pojo.Task;
import com.kaishengit.util.DateUtil;

public class TaskDao extends BaseDao<Task, String> {

	private List<Task> todayTask;
	private List<Task> outTask;
	private List<Task> futureTask;

	public List<Task> findTodayTask() {	
		findTask();
		return todayTask;
	}
	public List<Task> findOutTask() {		
		findTask();
		return outTask;
	}
	public List<Task> findfutureTask() {	
		findTask();
		return futureTask;
	}
	
	private void findTask() {
		List<Task> list = findAll();
		
		todayTask = new ArrayList<Task>();
		outTask = new ArrayList<Task>();
		futureTask = new ArrayList<Task>();
		
		for(Task task : list) {
			if(DateUtil.toToday(task.getEndDate()) < 0) {
				if (!task.isComplete()) {					
					outTask.add(task);
				}
			} else if(DateUtil.toToday(task.getStartDate()) >0) {
				futureTask.add(task);
			} else {
				todayTask.add(task);
			}
		}	
	}
}
